package com.example.qxfw.qxybzz.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.qxybzz.entity.PageBean;
import com.example.qxfw.qxybzz.entity.dto.PersonDto;
import com.example.qxfw.qxybzz.service.PublishObjectService;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;


/**
 * 发布对象
 */
@RestController
@RequestMapping("/pubishObject")
@RequiredArgsConstructor
public class PublishObjectController {

    private final PublishObjectService publishObjectService;


    /**
     * 分页查询人员对象
     */
    @PostMapping("/person")
    public SysResult getPagePerson(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pageSize,
                                   @RequestBody PersonDto personDto)
    {
        PageBean pageBean = publishObjectService.getPagePerson(personDto, page, pageSize);
       return SysResult.success(pageBean);
    }


    /**
     * 根据id删除人员对象
     */
    @DeleteMapping("/deletePerson")
    public SysResult deletePerson(@RequestParam Integer id)
    {
        publishObjectService.deletePerson(id);
        return SysResult.success();
    }


    /**
     * 批量删除人员
     */
    @DeleteMapping("/deletePersons")
    public SysResult deletePersons(@RequestBody Integer[] ids)
    {
        publishObjectService.deletePersons(ids);
        return SysResult.success();
    }


    /**
     * 新增人员
     */
    @PostMapping("/addPerson")
    public SysResult addPerson(@RequestBody PersonDto personDto)
    {
        publishObjectService.addPerson(personDto);
        return SysResult.success();
    }

    /**
     * 修改人员
     */
    @PutMapping("/updatePerson")
    public SysResult updatePerson(@RequestBody PersonDto personDto)
    {
        publishObjectService.updatePerson(personDto);
        return SysResult.success();
    }


}
